package com.ww.grtsmanager.controller;

import com.ww.grtsmanager.bean.Teacher;
import com.ww.grtsmanager.service.TeacherService;
import com.ww.grtsmanager.vo.Conditions;
import com.ww.grtsmanager.vo.EduResult;
import com.ww.grtsmanager.vo.TeacherResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @RequestMapping("/addTeacher")
    public EduResult addTeacher(@Valid @RequestBody Teacher teacher){
        teacherService.addTeacher(teacher);
        return EduResult.ok();
    }
    @RequestMapping("/showTeacher/{currentPage}/{limit}")
    public EduResult showTeacher(@PathVariable Integer currentPage, @PathVariable Integer limit, @RequestBody Conditions conditions){
        TeacherResult result = teacherService.showTeacher(currentPage,limit,conditions);
        return EduResult.ok(result);
    }
    @RequestMapping("/deleteTeacher/{id}")
    public EduResult deleteTeacher(@PathVariable Integer id){
        teacherService.deleteTeacher(id);
        return EduResult.ok();
    }
    @RequestMapping("/deleteTeacherAll")
    public EduResult deleteTeacherAll(@RequestParam("ids")List<Integer> ids){
        teacherService.deleteTeacherAll(ids);
        return EduResult.ok();
    }
    @RequestMapping("/getTeacher/{id}")
    public EduResult getTeacher(@PathVariable Integer id){
        Teacher teacher = teacherService.getTeacher(id);
        return EduResult.ok(teacher);
    }
    @RequestMapping("/updateTeacher")
    public EduResult updateTeacher(@Valid @RequestBody Teacher teacher){
        teacherService.updateTeacher(teacher);
        return EduResult.ok();
    }
    @RequestMapping("/getTeacherAll")
    public EduResult getTeacher(){
        List<Teacher> teacher = teacherService.getTeacherAll();
        return EduResult.ok(teacher);
    }
}
